package top.leinx.fxnotes.pane;

/**
 * @Author : xiaolei
 * @DateTime: 2021/3/19 1:48 下午
 */

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.text.TextAlignment;
import javafx.stage.Stage;

public class BorderPaneExample extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        BorderPane borderPane = new BorderPane();

        Pane top = new Pane();
        top.setPrefHeight(50.0);  // 设置top的高度。无需设置宽度，由borderPane调整
        top.setStyle("-fx-background-color: red;");

        Pane bottom = new Pane();
        bottom.setPrefHeight(50.0);  // 设置bottom的高度。无需设置宽度，由borderPane调整
        bottom.setStyle("-fx-background-color: red;");

        Pane left = new Pane();
        left.setPrefWidth(75.0);  // 设置left的宽度。无需设置高度，由borderPane调整
        left.setStyle("-fx-background-color: blue;");

        Pane right = new Pane();
        right.setPrefWidth(75.0);  // 设置right的宽度。无需设置高度，由borderPane调整
        right.setStyle("-fx-background-color: blue;");

        Pane center = new Pane();  // 无需设置宽度和高度，由borderPane调整
        center.setStyle("-fx-background-color: green;");

        // 把5个子节点分别设置到5个位置
        borderPane.setTop(top);
        borderPane.setBottom(bottom);
        borderPane.setCenter(center);
        borderPane.setLeft(left);
        borderPane.setRight(right);

        // borderPane.setBottom(null); // 某个位置设置为null，可以移除该位置的子节点
        primaryStage.setTitle("Border 示例");
        primaryStage.setScene(new Scene(borderPane, 400, 300));
        primaryStage.show();
    }
}
